package com.zzsoft.nettysocket;/**
 * Created by zhanghb on 2019/9/2.
 */

/**
 * @Description
 * @Author Zhanghb
 * @Date
 */

import java.io.BufferedInputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
    public Client() throws Exception {
        Socket socket = new Socket("localhost", 8001);

        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());

        byte[] buf = new byte[1024];

        System.out.println("开始读数据...");

        int count = bis.read(buf);
        System.out.println("读取数据数量:" + count);
        System.out.println(new String(buf));

        System.out.println("开始写数据...");
        PrintWriter out=new PrintWriter(socket.getOutputStream());
        for(int i =0 ;i<50;i++) {
            out.println("test"+i+"，测试"+i);
            out.flush();
            Thread.sleep(1000);
        }
        bis.close();
        //socket.close();
    }

    public static void main(String[] args) {
        try {
            new Client();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
